﻿using EM.Components.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using EM.Components.Entities;
using System.Security.Principal;

namespace EM.Components.Business.Tests
{
    
    
    /// <summary>
    ///This is a test class for CampaignProviderTest and is intended
    ///to contain all CampaignProviderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CampaignProviderTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        public void AddTest()
        {
            CampaignProvider target = new CampaignProvider(); // TODO: Initialize to an appropriate value
            EM_Campaigns entity = Create(); // TODO: Initialize to an appropriate value
            target.Add(entity);
            EM_Campaigns actual = target.Get(entity.CampaignID);
            Assert.AreEqual(true,actual.CampaignID>0);
        }

        private EM_Campaigns Create() 
        {
            EM_Campaigns entity = new EM_Campaigns();
            entity.CampaignName = DateTime.Now.Ticks.ToString()+"Name";
            entity.CampaignDesc = "Description for " + entity.CampaignName ;
            entity.StartDate = DateTime.Now;
            entity.EndDate = DateTime.Now.AddDays(10);
            entity.Owner = WindowsIdentity.GetCurrent().Name;
            entity.CreatedBy = entity.Owner;
            entity.CreatedDate = DateTime.Now;

            return entity;
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void AddTest1()
        {
            CampaignProvider target = new CampaignProvider(); // TODO: Initialize to an appropriate value
            EM_Campaigns entity = Create(); // TODO: Initialize to an appropriate value
            entity.CampaignName = "634829163472672802Name";
            target.Add(entity);
        }

        /// <summary>
        ///A test for Submit
        ///</summary>
        [TestMethod()]
        public void SubmitTest()
        {
            CampaignProvider target = new CampaignProvider(); // TODO: Initialize to an appropriate value
            EM_Campaigns entity = Create();
            EM_Campaigns actual= target.Add(entity);
            target.Submit(actual.CampaignID);
            var ex = target.Get(actual.CampaignID);
            Assert.AreEqual(true,ex.Submitted);
        }

        /// <summary>
        ///A test for Approved
        ///</summary>
        [TestMethod()]
        public void ApprovedTest()
        {
            CampaignProvider target = new CampaignProvider(); // TODO: Initialize to an appropriate value
            int entityId = 0; // TODO: Initialize to an appropriate value
            string user = string.Empty; // TODO: Initialize to an appropriate value
            EM_Campaigns entity = Create();
            var actual = target.Add(entity);
            entityId = actual.CampaignID;
            user = actual.Owner;
            target.Approve(entityId, user);
            var g = target.Get(entityId);
            Assert.AreEqual(true,g.Approved);
        }
    }
}
